package com.hexinfo.dmpro.dev.data.transfer.model;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Accessors(chain = true)
public class FtpTakeUp {

    private double takeUpSpace;

    private String takeUpUnit;

    private double totalSpace;

    private double percentSpace;

    private String lastRefreshTime;

    public double getPercentSpace() {
        BigDecimal takeUp = new BigDecimal(Double.toString(takeUpSpace));
        BigDecimal total = new BigDecimal(Double.toString(totalSpace));
        BigDecimal percent = null;
        if (StrUtil.equals(takeUpUnit, "GB")) {
            // takeUpSpace / ( totalSpace * 1024 ) * 100;
            percent = takeUp.divide(total.multiply(new BigDecimal("1024")), 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
        } else {
            percent = takeUp.divide(total, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
        }
        return  percent.doubleValue();
    }

    public String getLastRefreshTime() {
        return LocalDateTime.now().toString().substring(0, 19).replace("T", " ");
    }
}
